package com.zeng.service.impl;

import com.zeng.entity.Comments;
import com.zeng.dao.CommentsDao;
import com.zeng.service.CommentsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Comments)表服务实现类
 *
 * @author zengfanchao
 * @since 2021-04-11 16:43:03
 */
@Service("commentsService")
public class CommentsServiceImpl implements CommentsService {
    @Resource
    private CommentsDao commentsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param cid 主键
     * @return 实例对象
     */
    @Override
    public Comments queryById(Integer cid) {
        return this.commentsDao.queryById(cid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Comments> queryAllByLimit(int offset, int limit) {
        return this.commentsDao.queryAllByLimit(offset, limit);
    }

    @Override
    public List<Comments> queryAll(Comments comments) {
        return this.commentsDao.queryAll(comments);
    }

    /**
     * 新增数据
     *
     * @param comments 实例对象
     * @return 实例对象
     */
    @Override
    public Comments insert(Comments comments) {
        this.commentsDao.insert(comments);
        return comments;
    }

    /**
     * 修改数据
     *
     * @param comments 实例对象
     * @return 实例对象
     */
    @Override
    public Comments update(Comments comments) {
        this.commentsDao.update(comments);
        return this.queryById(comments.getCid());
    }

    /**
     * 通过主键删除数据
     *
     * @param cid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer cid) {
        return this.commentsDao.deleteById(cid) > 0;
    }

    @Override
    public List<Comments> selectAll() {
        return this.commentsDao.selectAll();
    }

    @Override
    public int queryCount() {
        return this.commentsDao.queryCount();
    }

    @Override
    public int queryCountSelect(String key) {
        return this.commentsDao.queryCountSelect(key);
    }

    @Override
    public List<Comments> queryKeyByLimit(String key, Integer offset, Integer limit) {
        return this.commentsDao.queryKeyByLimit(key, offset, limit);
    }

}
